local skel = fk.CreateSkill {
  name = "emo__yuhu",
  tags = {Skill.Compulsory}
}

skel:addEffect(fk.TurnStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    if not table.find(target:getEquipments(Card.SubtypeTreasure), function(cid) return Fk:getCardById(cid).name == "whitefox" end) then
      local max_num = player.hp
      for _, p in ipairs(player.room.alive_players) do
        max_num = math.max(max_num, p.hp)
      end
      if target.hp < max_num then return false end
      -- 考虑一下多个宝物栏情况
      return #target:getAvailableEquipSlots(Card.SubtypeTreasure) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardId = room:getTag("whitefox")
    if cardId == nil then
      cardId = table.find(room.void, function (id)
        return Fk:getCardById(id).name == "whitefox"
      end)
      if not cardId then
        cardId = room:printCard("whitefox", Card.Club, 10).id
      end
      room:setTag("whitefox", cardId)
    end
    if cardId and room:getCardArea(cardId) ~= Card.PlayerSpecial then
      local from = room:getCardOwner(cardId)
      if from and from ~= target then
        room:doIndicate(from.id, {target.id})
      end
      room:moveCardIntoEquip(target, cardId, skel.name, true, player)
    end
  end
})

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if Fk:getCardById(info.cardId).name == "whitefox" then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, skel.name)
  end
})

skel:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return target == player and data.skillName and string.find(data.skillName, "whitefox")
  end,
  on_use = function(self, event, target, player, data)
    local damage_num = data.damage
    data:preventDamage()
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = room:getOtherPlayers(player), min_num = 1, max_num = 1, skill_name = skel.name, cancelable = true,
      prompt = "#emo__yuhu-damage:::" .. damage_num,
    })
    if #tos > 0 then
      room:damage { from = player, to = tos[1], damage = damage_num, skillName = skel.name }
    end
  end
})

Fk:loadTranslationTable{
  ["emo__yuhu"] = "御狐",
  [":emo__yuhu"] = "锁定技，任意角色的回合开始时，若其体力值为最多之一，将<a href=':whitefox'>【白狐】</a>置入其装备区（替换原装备）。每当【白狐】移动时你摸一张牌。你受到【白狐】伤害时防止之，且你可转移给一名其他角色。",

  ["#emo__yuhu-damage"] = "御狐：你可以对一名其他角色造成 %arg 点伤害！",
}

return skel
